package com.tianqu.tms.www.user.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.UserClass;
import com.tianqu.tms.www.user.controller.UserCreationInputController;
import com.tianqu.tms.www.user.viewhelper.UserTopViewHelper;

/**
 * 用户添加首页jsp显示
 * 
 * @author tianshifu
 * 
 */

public class UserCreationInputAction extends TmsAction {
	
	private Logger logger = Logger.getLogger(UserCreationInputAction.class);
	
	private static final String USERCLASS = "userClass";
	private static final String USERINFO = "userInfo";
	private static final String FLAG = "flag";

	@SuppressWarnings("unchecked")
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#doAction was called.");

		UserCreationInputController uiController = new UserCreationInputController();
		uiController.execute(uc);
		UserTopViewHelper viewHelper = new UserTopViewHelper();
		if("1".equals(request.getParameter(FLAG))){
			viewHelper = (UserTopViewHelper)uc.getAttribute(USERINFO);
			UserClass code = UserClass.getInstance();
			viewHelper.setUserType(String.valueOf(code.getUserClassByUserClassName(viewHelper.getUserType())));
		}
		
				
		viewHelper.setUserTypeList((List)uc.getAttribute(USERCLASS));
		
		request.setAttribute(TmsConstants.VIEWHELP, viewHelper);
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
